using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using LevelData;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework;

namespace GGJ11
{
    //draw block
    class RenderingBlocks : RenderingGameObject
    {
        Level level;
        Texture2D block;
        

        public RenderingBlocks() { }
        public RenderingBlocks(ContentManager Content)
            : base(Content)
        {
            level = Content.ServiceProvider.GetService(typeof(Level)) as Level;
            block = Content.Load<Texture2D>("Tiles/block"+ level.numLevel.ToString());            
        }

        //draw block and platform
        public void Draw(GameTime gameTime, SpriteBatch sp, Vector2 visibleHArea, Vector2 visibleVArea)
        {
            for (int i = 0; i < level.blockList.Count; i++)
            {
                if (level.blockList[i].posX >= visibleHArea.X && level.blockList[i].posX <= visibleHArea.Y)
                {
                    if (level.blockList[i].posY >= visibleVArea.X && level.blockList[i].posY <= visibleVArea.Y)
                    {
                        sp.Draw(block, new Rectangle(level.blockList[i].posX * level.blockList[i].width, level.blockList[i].posY * level.blockList[i].height, level.blockList[i].width, level.blockList[i].height), Color.White);
                    }
                }
            }

            //for (int i = 0; i < level.platformList.Count; i++)
            //{
            //    sp.Draw(block0, new Rectangle(level.platformList[i].posX * level.platformList[i].width, level.platformList[i].posY * level.blockList[i].height, level.platformList[i].width, level.platformList[i].height), Color.White);
            //}

            base.Draw(gameTime, sp, visibleHArea, visibleVArea);
        }

        //update service when load a next level
        public void UpdateLevelService(ContentManager content)
        {
            level = content.ServiceProvider.GetService(typeof(Level)) as Level;
            block = content.Load<Texture2D>("Tiles/block" + level.numLevel.ToString());
            base.UpdateLevelService(content);
        }
    }
}
